package org.jeecg;

import lombok.extern.slf4j.Slf4j;
import org.java_websocket.client.WebSocketClient;
import org.jeecg.common.util.oConvertUtils;
//import org.jeecg.modules.demo.yy.Component.MyWebSocketClient;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.UnknownHostException;

/**
* 单体启动类
* 报错提醒: 未集成mongo报错，可以打开启动类上面的注释 exclude={MongoAutoConfiguration.class}
*/
@Slf4j
@SpringBootApplication
//@EnableAutoConfiguration(exclude={MongoAutoConfiguration.class})
public class JeecgSystemApplication extends SpringBootServletInitializer {

    public static void main(String[] args) throws UnknownHostException {
        // 使用SpringApplicationBuilder启动Spring Boot应用
        ConfigurableApplicationContext application = new SpringApplicationBuilder(JeecgSystemApplication.class)
                .run(args);

        // 获取环境变量和配置信息
        Environment env = application.getEnvironment();
        String ip = InetAddress.getLocalHost().getHostAddress();
        String port = env.getProperty("server.port");
        String path = env.getProperty("server.servlet.context-path");

        // 输出启动信息
        log.info("\n----------------------------------------------------------\n\t" +
                "Application Jeecg-Boot is running! Access URLs:\n\t" +
                "Local: \t\thttp://localhost:" + port + path + "/\n\t" +
                "External: \thttp://" + ip + ":" + port + path + "/\n\t" +
                "Swagger文档: \thttp://" + ip + ":" + port + path + "/doc.html\n" +
                "----------------------------------------------------------");

        // 启动WebSocket客户端
//        startWebSocketClient("ws://192.168.102.87:8443"); // 替换为你的WebSocket服务器地址
    }

    // 启动WebSocket客户端的方法
//    private static void startWebSocketClient(String uri) {
//        try {
//            WebSocketClient client = new MyWebSocketClient(new URI(uri));
//            client.connect();
//        } catch (URISyntaxException e) {
//            e.printStackTrace();
//        }
//    }

    // MyWebSocketClient类与之前的示例相同
    // ...

}